package com.android.equipment.adapter;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.android.equipment.R;
import com.android.equipment.dao.People;
import com.blankj.utilcode.util.ImageUtils;
import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

public class PeopleManagerAdapter extends BaseQuickAdapter<People, BaseViewHolder> {
    public PeopleManagerAdapter(int layoutResId) {
        super(layoutResId);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(@NonNull BaseViewHolder holder, People people) {
        String peoplePhoto = people.getPeoplePhoto();
        ImageView ivPhoto = holder.getView(R.id.iv_photo);
        if (!StringUtils.isEmpty(peoplePhoto)) {
            Glide.with(getContext())
                    .load("file://" + peoplePhoto) // 使用 file:// URI 加载本地图片
                    .into(ivPhoto);
        }

        holder.setText(R.id.tv_people_name, people.getPeopleName());
        holder.setText(R.id.tv_people_age, "(" + people.getPeopleAge() + ")");
        holder.setText(R.id.tv_people_sex, people.getPeopleSex() == 1 ? "男" : "女");
        holder.setText(R.id.tv_people_phone, "手机号：" + people.getPeoplePhone());
        holder.setText(R.id.tv_create_time, "创建时间：" + people.getAddTime());
        TextView tvUpdateTime = holder.getView(R.id.tv_update_time);
        if (!StringUtils.isEmpty(people.getUpdateTime())) {
            tvUpdateTime.setVisibility(View.VISIBLE);
            tvUpdateTime.setText("更新时间：" + people.getUpdateTime());
        } else {
            tvUpdateTime.setVisibility(View.GONE);
        }
    }
}
